<%--
Created by IntelliJ IDEA.
User: 陪你度过漫长岁月
Date: 2022/10/14
Time: 11:42
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>商品列表</title>
    <link href="../../component/pear/css/pear.css" rel="stylesheet"/>

    <style type="text/css">
        .layui-card-body{
            height: auto;
            white-space: normal;
        }
        .layui-form-checkbox i {
            position: absolute;
            right: 0;
            top: 27px;
            width: 30px;
            height: 28px;
            border: 1px solid #d2d2d2;
            border-left: none;
            border-radius: 0 2px 2px 0;
            color: #fff;
            font-size: 20px;
            text-align: center
        }
    </style>
</head>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<body class="pear-container">
<%--<div class="layui-card">--%>
<%--    <div class="layui-card-body">--%>
<%--        <form class="layui-form" action="">--%>
<%--            <div class="layui-form-item">--%>
<%--                <div class="layui-form-item layui-inline">--%>
<%--                    <label class="layui-form-label">商品名称</label>--%>
<%--                    <div class="layui-input-inline">--%>
<%--                        <input type="text" name="productName" id="productName" placeholder="请输入商品名称" class="layui-input">--%>
<%--                    </div>--%>
<%--                </div>--%>
<%--                <div class="layui-form-item layui-inline">--%>
<%--                    <label class="layui-form-label">价格</label>--%>
<%--                    <div class="layui-input-inline" style="width: 100px">--%>
<%--                        <input type="text" name="price" id="priceMin" placeholder="最低价格" class="layui-input" style="width: 100px">--%>
<%--                    </div>--%>
<%--                    <div class="layui-input-inline" style="width: 16px;margin-top: 8px">一</div>--%>
<%--                    <div class="layui-input-inline" style="width: 100px">--%>
<%--                        <input type="text" name="price" id="priceMax" placeholder="最高价格" class="layui-input" style="width: 100px">--%>
<%--                    </div>--%>
<%--                </div>--%>
<%--                <div class="layui-form-item layui-inline">--%>
<%--                    <label class="layui-form-label">颜色</label>--%>
<%--                    <div class="layui-input-inline">--%>
<%--                        <input type="text" name="color" id="color" placeholder="请输入颜色" class="layui-input">--%>
<%--                    </div>--%>
<%--                </div>--%>
<%--                <div class="layui-form-item layui-inline" style="margin-left: 50px">--%>
<%--&lt;%&ndash;                <div class="layui-form-item layui-inline" style="margin-left: 500px">&ndash;%&gt;--%>
<%--                    <button class="pear-btn pear-btn-md pear-btn-primary btn1" lay-submit lay-filter="role-query">--%>
<%--                        <i class="layui-icon layui-icon-search"></i>--%>
<%--                        查询--%>
<%--                    </button>--%>
<%--                    <button type="reset" class="pear-btn pear-btn-md btn2">--%>
<%--                        <i class="layui-icon layui-icon-refresh"></i>--%>
<%--                        重置--%>
<%--                    </button>--%>
<%--                </div>--%>
<%--            </div>--%>
<%--        </form>--%>
<%--    </div>--%>
<%--</div>--%>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="order-table" class="layui-table" lay-filter="order-table"></table>
    </div>
</div>

<script type="text/html" id="role-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
</script>

<script type="text/html" id="role-bar">
    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>
    </button>
    <button class="pear-btn pear-btn-warming pear-btn-sm" lay-event="power"><i
            class="layui-icon layui-icon-vercode"></i></button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i>
    </button>
</script>

<script type="text/html" id="role-enable">
    <input type="checkbox" name="enable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="role-enable" {{
           d.enable== true ? 'checked' : '' }} />
</script>

<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<div align="center">
    <%--    layui 禁用按钮属性 layui-btn-disabled--%>
</div>

<script type="text/html" id="imgtmp">
    <img class="img" src="{{d.mainImage}}" width="50px" height="50px">
</script>

<%--订单状态：0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；5->无效订单--%>
<script type="text/html" id="status">
    {{d.status==0 ? '待付款' :d.status==1 ? '待发货':d.status==2 ? '已发货':d.status==3 ? '已完成':d.status==4 ? '已关闭':'无效订单'}}

</script>

<script type="text/html" id="btnX">
    <button class="pear-btn pear-btn-primary pear-btn-md details" value="{{d.id}}" id="details{{d.id}}" style="margin-top: 17px">
        查看详情
    </button>
</script>

<script type="text/html" id="btnD">
    <button class="pear-btn pear-btn-primary pear-btn-md statusBtn" lay-skin="btn" id="statusBtn" style="margin-top: 17px">
        {{d.status==0 ? '关闭订单' : d.status==1 ? '订单发货':d.status==2||d.status==3 ? '订单追踪':"删除订单"}}
    </button>
</script>

<script>
    layui.use(['table', 'form', 'jquery', 'common'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;


        let MODULE_PATH = "operate/";

        let cols = [
            [
                {type: 'checkbox', title: '选择', width: 80, style: "", sort: false}
                , {field: 'id', title: '订单id', width: 90, sort: false}
                , {field: 'memberId', title: '米id', width: 100, sort: false}
                , {field: 'orderSn', title: '订单编号', width: 135, sort: false}
                , {field: 'createTime', title: '提交时间', width: 135, sort: false}
                , {field: 'payAmount', title: '应付金额', width: 90, sort: true}
                , {field: 'status', title: '订单状态',templet: "#status", width: 120, sort: true}
                , {field: '1', title: '详情', width: 120, toolbar:"#btnX",event: 'stick', sort: false}
            ]
        ]

        table.render({
            elem: '#order-table',
            url: '${pageContext.request.contextPath}/OrdersListServlet',
            page: true,
            cols: cols,
            skin: 'line',
            async: true,
            headers: {
                token: localStorage.token
            },
            request: {
                pageName: 'pageNo',
                limitName: 'pageSize',
            },
            toolbar: '#role-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        table.on('tool(order-table)', function (obj) {
            $.ajaxSettings.async=false;
            $.getJSON('${pageContext.request.contextPath}/OrderDetailsServlet',{id:obj.data.id},function (data) {

            })
            layer.open({
                type: 2,
                title: "订单详情",
                closeBtn: 1,
                area: [common.isModile() ? '100%' : '1000px', common.isModile() ? '100%' : '600px'], scrollbar: false,
                content: MODULE_PATH + 'orderSelect.jsp',
                offset: ['25','30'],
                end: function () {
                }
            });
        });

        form.on('submit(role-query)', function (data) {
            table.reload('order-table', {where: data.field})
            return false;
        });

        form.on('switch(role-enable)', function (obj) {
            layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
        });

        window.add = function () {
            layer.msg("待开发", {
                time: 2000,
                btn: ['确定']
            })
        }

        window.power = function (obj) {
            layer.open({
                type: 2,
                title: '授权',
                shade: 0.1,
                area: ['320px', '400px'],
                content: MODULE_PATH + 'edit.jsp'
            });
        }

        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['500px', '400px'],
                content: MODULE_PATH + 'edit.jsp'
            });
        }

        window.remove = function (obj) {
            layer.confirm('确定要删除该角色', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "remove/" + obj.data['roleId'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].roleId + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些用户', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + "batchRemove/" + ids,
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('order-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.refresh = function () {
            table.reload('order-table');
        }
    })
</script>
</body>
</html>
